package com.tepth.maintenancesystem.view;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.api.HttpClient;
import com.tepth.maintenancesystem.api.LoginService;
import com.tepth.maintenancesystem.bean.LoginObj;
import com.tepth.maintenancesystem.bean.MovieEntity;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpTestActivity extends AppCompatActivity implements View.OnClickListener{

    String vehicleOnlineResult;
    TextView resultTV;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http_test);
        Button clickMeBN=(Button)findViewById(R.id.btn_test);
        resultTV=(TextView)findViewById(R.id.result_TV);
        clickMeBN.setOnClickListener(this);
    }

    //进行网络请求
    private void getMovie(){
        new Thread() {
            public void run() {
                //http://dec.tepth.cn/vm/verification.ashx?action=Login&loginName=test&password=test&appName=smartFAM_apk&appVersion=1.0.1&osName=android&osVersion=5.1
                String url = String.format(HttpClient.BASE_URL+"verification.ashx?action=%s&loginName=%s&password=%s&appName=%s&appVersion=%s&osName=%s&osVersion=%s", "Login","test","test","smartFAM_apk","1.0.1","android","5.1");
                vehicleOnlineResult = HttpClient.sendGet(url, null);
                handler.sendEmptyMessage(0);
            };
        }.start();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    resultTV.setText(vehicleOnlineResult);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public void onClick(View view) {
        getMovie();
    }
}
